home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / source / dcselimg.mod < prev    next >
Text File  |  1997-04-16  |  12KB  |  323 lines

  1. IMPLEMENTATION MODULE DCSelImg;
  2.  
  3. (*---------------------------------------------------------------------*)
  4. (*   Select Rectangular portion of the picture. Update PicImage        *)
  5. (*   Dialog with selected values.                                      *)
  6. (*                                                                     *)
  7. (*   Assumptions:                                                      *)
  8. (*      1) This routine does not have to rebuild the screen.           *)
  9. (*      2) The right mouse button pressed at any time will abort.      *)
  10. (*                                                                     *)
  11. (*   The order of things happening is:                                 *)
  12. (*      1) Draw a rubber box of approximate size.                      *)
  13. (*         The box can be dragged and resized as follows:              *)
  14. (*         If click and hold within box then                           *)
  15. (*            if within lower 1/3 pixels of bottom left corner then    *)
  16. (*               resize box                                            *)
  17. (*            else                                                     *)
  18. (*               drag the box                                          *)
  19. (*         else                                                        *)
  20. (*            if left button then                                      *)
  21. (*               update picture image                                  *)
  22. (*            else                                                     *)
  23. (*               leave                                                 *)
  24. (*            endif                                                    *)
  25. (*         endif                                                       *)
  26. (*                                                                     *)
  27. (*                                                                     *)
  28. (*   Version 1.00     August 1988                    L.G.Miller        *)
  29. (*---------------------------------------------------------------------*)
  30.  
  31. (* IMPORT  Trace; *)
  32.  
  33.  
  34. FROM    DCGlobal                IMPORT PictureImage,
  35.                                        HiRes, MedRes,
  36.                                        MedResMaxX, MedResMaxY,
  37.                                        HiResMaxX,  HiResMaxY,
  38.                                        HiResScreen;
  39.  
  40. FROM    DCScreen                IMPORT DisplayFullPicture;
  41.  
  42. FROM    ManyWindow         IMPORT ShowMouse,
  43.                                        HideMouse,
  44.                                        VDIHandle;
  45.  
  46.  
  47. IMPORT  Graphics;
  48.  
  49. IMPORT  Event;
  50.  
  51.  
  52. FROM    VDI                     IMPORT vswr_mode,
  53.                                        vsl_type,
  54.                                        vsl_color,
  55.                                        vsl_udsty,
  56.  
  57.                                        vs_clip,
  58.  
  59.                                        v_pline;
  60.  
  61. TYPE
  62.     PxyArrayType    = ARRAY [ 0 ..   3 ] OF INTEGER;
  63.         RGBArrayType    = ARRAY [ 0 ..   3 ] OF INTEGER;
  64.  
  65.  
  66. CONST
  67.         CMinWidth        =  20;
  68.         CMinHeight       =  20;
  69.         CStartWidth      = 200;
  70.         CStartHeight     = 100;
  71.         CStretchRange    =  10;
  72.         CVDIXorWriteMode =   3;
  73.         CLineType        =   7; (* user line *)
  74.  
  75.         FlatHand     =   4;
  76.         PointHand     =   3;
  77.         Arrow         =   0;
  78.  
  79.  
  80. PROCEDURE QueryOutsideBox ( mox, moy,
  81.                             boxx, boxy, boxw, boxh : INTEGER ): BOOLEAN;
  82.  
  83.   BEGIN
  84.     IF ( mox < boxx ) OR ( mox > ( boxx + boxw - 1 ) ) THEN
  85.       RETURN TRUE
  86.     END;
  87.     IF ( moy < boxy ) OR ( moy > ( boxy + boxh - 1 ) ) THEN
  88.       RETURN TRUE
  89.     END;
  90.     RETURN FALSE;
  91.   END QueryOutsideBox;
  92.  
  93.  
  94. (*----------------------------------------------------------------------*)
  95. (* If mouse in lower third of box then will select.                     *)
  96. (*----------------------------------------------------------------------*)
  97. PROCEDURE QueryStretchBox( mox, moy,
  98.                           boxx, boxy, boxw, boxh : INTEGER ) : BOOLEAN;
  99.     VAR w, h : INTEGER;
  100.   BEGIN
  101.     w := boxw DIV 3;
  102.     h := boxh DIV 3;
  103.     boxx := ( boxx + boxw - 1 ) - w;
  104.     boxy := ( boxy + boxh - 1 ) - h;
  105.     RETURN NOT QueryOutsideBox( mox, moy, boxx, boxy, w, h );
  106.   END QueryStretchBox;
  107.  
  108.  
  109. PROCEDURE WaitMouseButton ( VAR mox, moy, mstate, kstate : CARDINAL );
  110.   CONST  CMButtons = {14,15};
  111.   VAR dumc : CARDINAL;
  112.   BEGIN
  113.     mstate := 0;
  114.     REPEAT
  115.       dumc := Event.evnt_timer( LONGCARD(0) ); (* give other tasks chance to run *)
  116.       dumc := Graphics.graf_mkstate( mox, moy, mstate, kstate );
  117.       mstate := INTEGER( BITSET(mstate) * CMButtons );
  118.                                  (* do bitwise AND mask *)
  119.     UNTIL ( ( mstate # 0 ) & ( moy > 15 ) );
  120.   END WaitMouseButton;
  121.  
  122.  
  123. PROCEDURE WaitNoMouseButton;
  124.   CONST  CMButtons = {14,15};
  125.   VAR mox, moy, mstate, dummy : CARDINAL;
  126.   BEGIN
  127.     mstate := 0;
  128.     REPEAT
  129.       dummy := Event.evnt_timer( LONGCARD(0) ); (* give other tasks time to run *)
  130.       dummy := Graphics.graf_mkstate( mox, moy, mstate, dummy );
  131.       mstate := INTEGER( BITSET(mstate) * CMButtons );
  132.                                          (* do bitwise AND mask *)
  133.     UNTIL ( ( mstate = 0 ) & ( moy > 15 ) );
  134.   END WaitNoMouseButton;
  135.  
  136.  
  137. PROCEDURE DrawXorBox( boxx, boxy, boxw, boxh : INTEGER );
  138.   VAR BoxCoords : ARRAY [ 0 .. 11 ] OF INTEGER;
  139.   BEGIN
  140.     HideMouse;
  141.     BoxCoords[0] := boxx;
  142.     BoxCoords[1] := boxy;
  143.     BoxCoords[2] := boxx + boxw - 1;
  144.     BoxCoords[3] := boxy;
  145.     v_pline( VDIHandle, 2, BoxCoords ); (* top horizontal *)
  146.     BoxCoords[0] := boxx + boxw - 1;
  147.     BoxCoords[1] := boxy+1;
  148.     BoxCoords[2] := BoxCoords[0];
  149.     BoxCoords[3] := boxy + boxh - 1;
  150.     v_pline( VDIHandle, 2, BoxCoords ); (* right vert *)
  151.     BoxCoords[0] := boxx;
  152.     BoxCoords[1] := boxy + boxh - 1 ;
  153.     BoxCoords[2] := boxx + boxw - 2 ;
  154.     BoxCoords[3] := BoxCoords[1];
  155.     v_pline( VDIHandle, 2, BoxCoords ); (* bottom horiz *)
  156.     BoxCoords[0] := boxx;
  157.     BoxCoords[1] := boxy + 1;
  158.     BoxCoords[2] := boxx ;
  159.     BoxCoords[3] := boxy + boxh - 2;     (* left vert *)
  160.     v_pline( VDIHandle, 2, BoxCoords );
  161.     ShowMouse;
  162.   END DrawXorBox;
  163.  
  164.  
  165. (*----------------------------------------------------------------------*)
  166. (* Having problems with GrafRubberBox if start is too near top of       *)
  167. (* screen, so will start with a box in the middle of the screen.        *)
  168. (* I have no idea why it doesn't work properly yet.                     *)
  169. (*----------------------------------------------------------------------*)
  170. PROCEDURE DoMedResSelectImage ( VAR PictureImageDetails : PictureImage;
  171.                                 VAR Picture             : HiResScreen  );
  172.  CONST CRButton = 2;
  173.        CLButton = 1;
  174.  
  175.  
  176.  VAR mox, moy, mbutton, bkstate    : CARDINAL;
  177.     boxx, boxy, boxw, boxh, mstate : CARDINAL;
  178.     dumi, i                        : INTEGER;
  179.     cliprect                       : PxyArrayType;
  180.     RGB                            : RGBArrayType;
  181.  BEGIN
  182.    dumi := vswr_mode( VDIHandle, CVDIXorWriteMode );
  183.    dumi := vsl_type( VDIHandle, CLineType );
  184.    vsl_udsty( VDIHandle, CARDINAL(0AAAAH) );
  185.    dumi := vsl_color( VDIHandle, 0 );
  186.  
  187.    cliprect[0] := 0;
  188.    cliprect[1] := 0;
  189.    cliprect[2] := MedResMaxX;
  190.    cliprect[3] := MedResMaxY;
  191.    vs_clip( VDIHandle, TRUE, cliprect );
  192.    HideMouse;
  193.    DisplayFullPicture( Picture );
  194.    ShowMouse;
  195.  
  196.    WaitNoMouseButton;
  197.  
  198.    boxx := ( MedResMaxX DIV 2 ) - ( CStartWidth  DIV 2 );
  199.    boxy := ( MedResMaxY DIV 2 ) - ( CStartHeight DIV 2 );
  200.    boxw := CStartWidth;
  201.    boxh := CStartHeight;
  202.  
  203.    LOOP
  204.       DrawXorBox( boxx, boxy, boxw, boxh );
  205.       WaitMouseButton( mox, moy, mbutton, bkstate );
  206.       DrawXorBox( boxx, boxy, boxw, boxh );
  207.  
  208.       IF ( mbutton = CRButton ) THEN
  209.         WaitNoMouseButton;
  210.         RETURN
  211.       END; (* right button = abort *)
  212.  
  213.       (* outside box? ... accept rectangle if true *)
  214.       IF QueryOutsideBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
  215.          EXIT
  216.       END; (* if *)
  217.  
  218.       IF QueryStretchBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
  219.          dumi := Graphics.graf_mouse(PointHand, NIL);
  220.          dumi := Graphics.graf_rubberbox( boxx, boxy, CMinWidth, CMinHeight,
  221.                                           boxw, boxh );
  222.          dumi := Graphics.graf_mouse(Arrow ,NIL);
  223.       ELSE
  224.          dumi := Graphics.graf_mouse(FlatHand, NIL);
  225.          dumi := Graphics.graf_dragbox( boxw, boxh, boxx, boxy,
  226.                                         0, 0, MedResMaxX+1, MedResMaxY+1,
  227.                                         boxx, boxy );
  228.          dumi := Graphics.graf_mouse(Arrow, NIL);
  229.       END; (* if *)
  230.  
  231.    END; (* loop *)
  232.  
  233.    (* convert med res values to hi-res *)
  234.    WITH  PictureImageDetails DO
  235.       StartX := boxx;
  236.       StartY := boxy * 2;
  237.       Width  := boxw;
  238.       Height := boxh * 2;
  239.    END; (* with *)
  240.    vs_clip( VDIHandle, FALSE, cliprect );
  241.    WaitNoMouseButton;
  242.  END DoMedResSelectImage;
  243.  
  244.  
  245.  
  246. PROCEDURE DoHiResSelectImage ( VAR PictureImageDetails : PictureImage;
  247.                                VAR Picture             : HiResScreen );
  248.  CONST CRButton = 2;
  249.        CLButton = 1;
  250.  
  251.  
  252.  VAR mox, moy, mbutton, bkstate     : CARDINAL;
  253.     boxx, boxy, boxw, boxh, mstate  : CARDINAL;
  254.     dumi                            : INTEGER;
  255.     cliprect                        : PxyArrayType;
  256.  BEGIN
  257.    dumi := vswr_mode( VDIHandle, CVDIXorWriteMode );
  258.    dumi := vsl_type( VDIHandle, CLineType );
  259.    vsl_udsty( VDIHandle, CARDINAL(0AAAAH) );
  260.    dumi := vsl_color( VDIHandle, 0 );
  261.  
  262.    cliprect[0] := 0;
  263.    cliprect[1] := 0;
  264.    cliprect[2] := HiResMaxX;
  265.    cliprect[3] := HiResMaxY;
  266.    vs_clip( VDIHandle, TRUE, cliprect );
  267.    HideMouse;
  268.    DisplayFullPicture( Picture );
  269.    ShowMouse;
  270.  
  271.    WaitNoMouseButton;
  272.  
  273.    boxx := ( HiResMaxX DIV 2 ) - ( CStartWidth  DIV 2 );
  274.    boxy := ( HiResMaxY DIV 2 ) - ( CStartHeight DIV 2 );
  275.    boxw := CStartWidth;
  276.    boxh := CStartHeight;
  277.  
  278.    LOOP  (* leave on right button OR Left button outside box *)
  279.       DrawXorBox( boxx, boxy, boxw, boxh );
  280.       WaitMouseButton( mox, moy, mbutton, bkstate );
  281.       DrawXorBox( boxx, boxy, boxw, boxh );
  282.  
  283.       IF ( mbutton = CRButton ) THEN
  284.          WaitNoMouseButton;
  285.          RETURN
  286.       END; (* quit *)
  287.  
  288.       (* outside box? ... accept rectangle if true *)
  289.       IF QueryOutsideBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
  290.          EXIT
  291.       END; (* if *)
  292.  
  293.       IF QueryStretchBox( mox, moy, boxx, boxy, boxw, boxh ) THEN
  294.          dumi := Graphics.graf_mouse(PointHand, NIL);
  295.          dumi := Graphics.graf_rubberbox( boxx, boxy, CMinWidth, CMinHeight,
  296.                                           boxw, boxh );
  297.  
  298.          dumi := Graphics.graf_mouse(Arrow, NIL);
  299.       ELSE
  300.          dumi := Graphics.graf_mouse(FlatHand, NIL);
  301.          dumi := Graphics.graf_dragbox( boxw, boxh, boxx, boxy,
  302.                                         0, 0,
  303.                                         HiResMaxX+1, HiResMaxY+1,
  304.                                         boxx, boxy );
  305.          dumi := Graphics.graf_mouse(Arrow, NIL);
  306.       END;
  307.    END; (* loop *)
  308.  
  309.    WITH  PictureImageDetails DO
  310.       StartX := boxx;
  311.       StartY := boxy;
  312.       Width  := boxw;
  313.       Height := boxh;
  314.    END; (* with *)
  315.    vs_clip( VDIHandle, FALSE, cliprect );
  316.    WaitNoMouseButton;
  317.  END DoHiResSelectImage;
  318.  
  319.  
  320.  
  321. END DCSelImg.
  322.  
  323.